package smedi.ismedi.mobile.bff.controller.dictionary;

import com.smedi.ismedi.dictionary.dto.request.AddDictionaryItemRequest;
import com.smedi.ismedi.dictionary.dto.request.AddDictionaryTypeRequest;
import com.smedi.ismedi.dictionary.dto.request.UpdateDictionaryItemRequest;
import com.smedi.ismedi.dictionary.dto.request.UpdateDictionaryTypeRequest;
import com.smedi.ismedi.dictionary.dto.response.DictionaryItemResponse;
import com.smedi.ismedi.dictionary.dto.response.DictionaryTypeResponse;
import com.smedi.ismedi.dictionary.feign.RemoteDictionaryFeignApi;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import smedi.ismedi.mobile.bff.controller.BaseController;

import javax.validation.constraints.NotNull;

/**
 * @Author Jimmy
 * @Date 2021/6/1 16:19
 */
@Api(value = "数据字典管理", tags = {"数据字典管理"})
@RequestMapping(value = "/mobilebff/v1/dictionary")
@RestController
@AllArgsConstructor
public class DictionaryController extends BaseController {
    private final RemoteDictionaryFeignApi dictionaryFeignApi;

    /**
     * 添加字典项类型
     *
     * @param addDictionaryTypeRequest
     * @return
     */
    @ApiOperation(value = "添加字典项类型", nickname = "添加字典项类型")
    @PostMapping(value = "/addType")
    ResponseData<DictionaryTypeResponse> addDictionaryType(@ApiParam(value = "param", required = true) @RequestBody AddDictionaryTypeRequest addDictionaryTypeRequest) {
        return dictionaryFeignApi.addDictionaryType(addDictionaryTypeRequest);
    }

    /**
     * 添加字典项
     *
     * @param addDictionaryItemRequest
     * @return
     */
    @ApiOperation(value = "添加字典项", nickname = "添加字典项")
    @PostMapping(value = "/addItem")
    ResponseData<DictionaryItemResponse> addDictionaryItem(@ApiParam(value = "param", required = true) @RequestBody AddDictionaryItemRequest addDictionaryItemRequest) {
        return dictionaryFeignApi.addDictionaryItem(addDictionaryItemRequest);
    }


    /**
     * 根据Id删除字典项类型
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据Id删除字典项类型", nickname = "根据Id删除字典项类型")
    @DeleteMapping(value = "/deleteTypeById")
    ResponseData<Boolean> deleteDictionaryTypeById(@NotNull @ApiParam(value = "id", required = true)
                                                   @RequestParam(value = "id", required = true) Long id) {
        return dictionaryFeignApi.deleteDictionaryTypeById(id);
    }

    /**
     * 根据Id删除字典项
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据Id删除字典项", nickname = "根据Id删除字典项")
    @DeleteMapping(value = "/deleteItemById")
    ResponseData<Boolean> deleteDictionaryItemById(@NotNull @ApiParam(value = "id", required = true)
                                                   @RequestParam(value = "id", required = true) Long id) {
        return dictionaryFeignApi.deleteDictionaryItemById(id);
    }

    /**
     * 更新字典项类型
     *
     * @param updateDictionaryRequest
     * @return
     */
    @ApiOperation(value = "更新字典项类型", nickname = "更新字典项类型")
    @PutMapping(value = "/updateType")
    ResponseData<DictionaryTypeResponse> updateDictionaryType(@ApiParam(value = "param", required = true)
                                                              @RequestBody UpdateDictionaryTypeRequest updateDictionaryRequest) {
        return dictionaryFeignApi.updateDictionaryType(updateDictionaryRequest);
    }

    /**
     * 更新字典项
     *
     * @param updateDictionaryItemRequest
     * @return
     */
    @ApiOperation(value = "更新字典项", nickname = "更新字典项")
    @PutMapping(value = "/updateItem")
    ResponseData<DictionaryItemResponse> updateDictionaryItem(@ApiParam(value = "param", required = true)
                                                              @RequestBody UpdateDictionaryItemRequest updateDictionaryItemRequest) {
        return dictionaryFeignApi.updateDictionaryItem(updateDictionaryItemRequest);
    }

}
